import type { Dayjs } from 'dayjs';

import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace LawCaseContentApi {
  /** 案件详细内容信息 */
  export interface CaseContent {
    id: string; // 案件id
    contentHash?: string; // 内容SHA256哈希
    caseNo?: string; // 案号
    caseCause?: string; // 案由
    trialProcedure?: string; // 审理程序（一审/二审/再审等）
    courtName?: string; // 审理法院
    judgmentDate?: Dayjs | string; // 裁判时间
    partyInfo: object; // 当事人信息结构化数据(zlib压缩)
    judgmentResult: string; // 裁判结果
    disputeFocus: object; // 争议焦点(zlib压缩)
    caseSummary: object; // 案件概述(zlib压缩)
    courtFindings: object; // 法院查明(zlib压缩)
    courtOpinion: object; // 法院认为(zlib压缩)
    fullText: object; // 全文压缩
    textLength: object; // 原文长度
    judicialRules: string; // 适用法条
  }
}

/** 查询案件详细内容分页 */
export function getCaseContentPage(
  data: PageParam,
  desensitize: boolean,
  encrypt: boolean,
) {
  return requestClient.post<PageResult<LawCaseContentApi.CaseContent>>(
    '/law/case-content/page',
    data,
    { desensitize, encrypt },
  );
}

/** 查询案件详细内容详情 */
export function getCaseContent(id: string) {
  return requestClient.get<LawCaseContentApi.CaseContent>(
    `/law/case-content/get?id=${id}`,
  );
}

/** 新增案件详细内容 */
export function createCaseContent(data: LawCaseContentApi.CaseContent) {
  return requestClient.post('/law/case-content/create', data);
}

/** 修改案件详细内容 */
export function updateCaseContent(data: LawCaseContentApi.CaseContent) {
  return requestClient.put('/law/case-content/update', data);
}

/** 删除案件详细内容 */
export function deleteCaseContent(id: string) {
  return requestClient.delete(`/law/case-content/delete?id=${id}`);
}

/** 批量删除案件详细内容 */
export function deleteCaseContentList(ids: string[]) {
  return requestClient.delete(
    `/law/case-content/delete-list?ids=${ids.join(',')}`,
  );
}

/** 导出案件详细内容 */
export function exportCaseContent(params: any) {
  return requestClient.download('/law/case-content/export-excel', { params });
}
